<!--
 * @Author: weidewei
 * @Date: 2025-11-18 14:35:32
 * @LastEditors: weidewei
 * @LastEditTime: 2025-11-19 10:55:34
 * @Description: 
 * @FilePath: \2025-front-face\html&css\水平垂直居中.html
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }
    /* flex 
    .parent {
        width: 300px;
        height: 300px;
        border: 1px solid red;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    .child {
        width: 100px;
        height: 100px;
        border: 1px solid;
    } */

     /* grid 
     .parent {
        width: 300px;
        height: 300px;
        border: 1px solid red;
        display: grid;
        justify-content: center;
        align-items: center;
    }
    .child {
        width: 100px;
        height: 100px;
        border: 1px solid;
    } */
     
    
     /* .parent {
        width: 300px;
        height: 300px;
        border: 1px solid red;
        position: relative;
    }
    .child {
        width: 100px;
        height: 100px;
        border: 1px solid;
        position: absolute;
        left: 50%;
        top: 50%;
        margin-left: -50px;
        margin-top: -50px;
    } */
    
    
     .parent {
        width: 300px;
        height: 300px;
        border: 1px solid red;
        position: relative;
    }
    .child {
        width: 100px;
        height: 100px;
        border: 1px solid;
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%,-50%);
    }
</style>
<body>
    <div class="parent">
        <div class="child"></div>
    </div>
</body>
</html>